#!/bin/bash
# 使/etc/profile 配置生效,否则java需要用全路径
source /etc/profile
# 进入jar目录
cd /app/boss/target
# 为脚本添加可执行权限
chmod 755 ../deploy.sh
# 防止进程被杀死,采用maven工程进行构建，修改BUILD_ID无效，后台进程随着jenkins构建完成后仍被杀死
export BUILD_ID=dontKillMe

# force copy
alias cp='cp'
alias mv='mv'
# backup last version
if [ -f summer_boss_backend.cur.jar ]; then
  cp summer_boss_backend.cur.jar summer_boss_backend.last.jar
fi
# generate deploy jar package
mv summer_boss_backend.jar summer_boss_backend.cur.jar

alias cp='cp -i'
alias mv='mv -i'
# if the service is running, just stop it.
pid=`ps -ef | grep summer_boss_backend.cur.jar | grep -v grep | awk '{print $2}'`
if [[ $pid -gt 0 ]]; then
  kill -9 $pid
fi
# start the service at backend
echo "summer boss backend service starting"
java -Xms100m -Xmx100m -Xss256k -Dspring.profiles.active=prd -jar summer_boss_backend.cur.jar | exit 0 &
sleep 10s
echo "summer boss backend service started"
# watch service log
# tail -200f /app/logs/boss/boss.log


